<?php

namespace app\home\controller;
use app\home\controller\Base;
class Photo extends Base
{
    public function index(){
        return view('list');
    }
    public function getPhotoList(){
        $map=["status"=>1];
        $cid=input('cid',0,'intval');
        if ($cid){
            $map["cid"]=$cid;
        }
        $map["order"]='id desc';
		$map['limit'] = '40';
		$model = model('Photo');
		$ret = $model->getList($map);
		//P($ret['list']);
		echo json_encode($ret['list']);
        //echo json_encode($ret['data']);
    }
    public function save($model=false,$data=null){
        $ret = model('Photo')->data(I('post.'))->add();
    }
    function getList(){
        $cid = input('cid','','intval');
        if($cid){
            $map='module="Photo" and id='.$cid;
        }else{
            $map ='module="Photo"';
            $ret =array(
                'code'=>1,
                'album'=>'全部相片',
                'thumbList'=>array(),
            );
        }
        //$cl=M('Category')->where($map)->Order('id desc')->select();
        $Photo = model('Photo');
        $list = $Photo->Field('id,title,create_time as time,title as `desc`,concat(\'http://sssui.u.qiniudn.com/\',`img`,\'-photo\') as thumb,concat(\'http://sssui.u.qiniudn.com/\',`img`) as large')->Order('id desc')->select();
        //echo $Photo->getlastsql();
        foreach ($list as $k => $v) {
            $list[$k]['user'] ='Cansnow';
            $list[$k]['avatar'] ='Cansnow';
            $list[$k]['time'] =date('Y-m-d H:i:s',$v['time']);
        }
        $ret['thumbList']=$list;
        echo json_encode($ret);
    }
}
